﻿using System.Web.UI;
using System.Web.UI.WebControls;
using Ue.Framework.Web.WebControls;
using Ue.Infrastructure.Web.UI;
using Ue.Qcdz.Domain.TheSiteConfig;

namespace Ue.Qcdz.UI.Controls
{
    public class SiteConfigEdit : SkinnedEntityEdit<SiteConfig>
    {
        private string skinFileName = "~/Admin/Themes/Skins/TheSiteConfig/SiteConfigEdit.ascx";
        private TextBox tbxCopyright;
        private TextBox tbxContact;
        private TextBox tbxEmail;
        private TextBox tbxComplaint;
        private TextBox tbxRecord;
        private TextBox tbxCopyrightEn;
        private TextBox tbxSiteName;
        private TextBox tbxMetaKeyworld;
        private TextBox tbxMetaDescription;

        #region Overrides of SkinnedControl

        protected override string GetSkinFileName()
        {
            return skinFileName;
        }

        #endregion

        #region Overrides of SkinnedEntityEdit<SiteConfig>

        protected override void InitSkin(Control skin)
        {
            tbxCopyright = skin.FindControl<TextBox>("tbxCopyright");
            tbxContact = skin.FindControl<TextBox>("tbxContact");
            tbxEmail = skin.FindControl<TextBox>("tbxEmail");
            tbxComplaint = skin.FindControl<TextBox>("tbxComplaint");
            tbxRecord = skin.FindControl<TextBox>("tbxRecord");
            tbxCopyrightEn = skin.FindControl<TextBox>("tbxCopyrightEn");
            tbxSiteName = skin.FindControl<TextBox>("tbxSiteName");
            tbxMetaKeyworld = skin.FindControl<TextBox>("tbxMetaKeyworld");
            tbxMetaDescription = skin.FindControl<TextBox>("tbxMetaDescription");

        }

        protected override SiteConfig Enttiy
        {
            get { 
                string copyright = tbxCopyright.GetValue<string>();
                string contact = tbxContact.GetValue<string>();
                string email = tbxEmail.GetValue<string>();
                string complaint = tbxComplaint.GetValue<string>();
                string record = tbxRecord.GetValue<string>();
                string copyrightEn = tbxCopyrightEn.GetValue<string>();
                return new SiteConfig(tbxSiteName.GetValue<string>(),tbxMetaKeyworld.GetValue<string>(),tbxMetaDescription.GetValue<string>(),copyright, contact,email,complaint,record,copyrightEn,this.EntityKey);
            }
            set
            {
                if(value==null)
                    return;
                tbxCopyright.SetValue(value.Copyright);
                tbxContact.SetValue(value.Contact);
                tbxEmail.SetValue(value.Email);
                tbxComplaint.SetValue(value.Complaint);
                tbxRecord.SetValue(value.Record);
                tbxCopyrightEn.SetValue(value.CopyrightEn);
                tbxSiteName.SetValue(value.SiteName);
                tbxMetaKeyworld.SetValue(value.MetaKeyworld);
                tbxMetaDescription.SetValue(value.MetaDescription);
            }
        }

        #endregion
    }
}
